import { activityRegisterOrderBatchVerify } from '@/api/activity/activity'
import {
    RefundApprovalStatusEnum,
} from '@/enums/activity'
export default {
    methods: {
        async batchVerify({ title, ids, status, callback }) {
            if (!ids.length) {
                return this.$message.warning('请选择要驳回的申请！');
            }
            // 通过
            if (status === RefundApprovalStatusEnum.APPROVED) {
                await activityRegisterOrderBatchVerify({ registerIds: ids, status: RefundApprovalStatusEnum.APPROVED })
                callback && callback()
                return;
            }
            // 驳回
            let remarks = ''
            this.$confirm({
                title,
                width: 600,
                icon: 'exclamation-circle',
                content: h => {
                    return h('div', {
                        style: {
                            display: 'flex',
                            paddingTop: '20px'
                        }
                    }, [
                        h('span', {
                            style: {
                                whiteSpace: 'nowrap'
                            }
                        }, '驳回原因：'),
                        h('a-textarea', {
                            style: {
                                width: '100%',
                                height: '100px',
                                marginLeft: '10px'
                            },
                            attrs: {
                                placeholder: '请输入驳回原因',
                            },
                            rows: 4,
                            on: {
                                change: (e) => {
                                    remarks = e.target.value
                                }
                            }
                        })
                    ]);
                },
                okText: `确定驳回`,
                cancelText: '取消',
                centered: true,
                onOk: () => {
                    return new Promise(async (resolve, reject) => {
                        try {
                            await activityRegisterOrderBatchVerify({ registerIds: ids, remarks, status: RefundApprovalStatusEnum.REJECTED })
                            callback && callback()
                            resolve()
                        } catch (error) {
                            reject(error)
                            return
                        }
                    })
                }
            })
        }
    },
};